package com.chenglai.pay.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;


/**
 * @author yawang
 * @create 2023/11/28 14:29:56
 **/
@Configuration
public class MqConfig {
    /**
     * 读取配置文件中的信息对象
     */
    @Autowired
    private Environment env;

    /**
     * 创建队列
     * @return
     */
    @Bean
    public Queue orderQueue(){
        return new Queue(env.getProperty("mq.pay.queue.order"));
    }

    /**
     * 创建交换机
     * @return
     */
    @Bean
    public TopicExchange orderExchange(){
        return new TopicExchange(env.getProperty("mq.pay.exchange.order"),true,false);
    }

    @Bean
    public Binding orderQueueExchange(Queue orderQueue, Exchange orderExchange){
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(env.getProperty("mq.pay.routing.key")).noargs();


    }
}
